package cn.net.shuxing.yifu.common.dto;


import cn.net.shuxing.yifu.common.constant.CodeConst;
import com.github.pagehelper.Page;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

@ApiModel(description = "返回结果")
@Data
public class BaseDto {
    //异常代码,0正常
    @ApiModelProperty("是否成功: 0成功，1失败")
    private int code = CodeConst.OK;

    //异常信息
    @ApiModelProperty("错误原因")
    private String msg = "";

    //返回的具体信息
    @ApiModelProperty("业务数据")
    private Object data;

    @ApiModelProperty("分页信息")
    private Page page;

    public static BaseDto error(String msg) {
        BaseDto baseDto = new BaseDto();
        baseDto.setCode(CodeConst.ERROR);
        baseDto.setMsg(msg);
        return baseDto;
    }

    public static BaseDto ok(Object data) {
        BaseDto baseDto = new BaseDto();
        baseDto.setCode(CodeConst.OK);
        baseDto.setData(data);
        return baseDto;
    }

    public boolean isError() {
        return code == CodeConst.ERROR;
    }

}
